package com.example.weixinpayment.result;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: weixin-payment
 * @description: 返回对象 @Accessors(chain = true)链式操作
 * @author: LiuZhuzheng
 * @create: 2021-12-28 17:26
 **/
@Data
@Accessors(chain = true)
public class Result {
    /**
     * 响应码
     * */
    private Integer code;
    /**
     * 响应消息
     * */
    private String message;
    /**
     * 响应数据
     * */
    Map<String, Object> data = new HashMap<>();

    public static Result success(){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage("成功");
        return result;
    }

    public static Result fail(){
        Result result = new Result();
        result.setCode(ResultCode.FAIL.getCode());
        result.setMessage("失败");
        return result;
    }

    public Result data(String key, Object value){
        this.data.put(key, value);
        return this;
    }
}
